<!-- 屈光发育档案/角塑复查(复查预警) -->
<template>
  <div class="mod-config">
    <el-form inline ref="searchForm" :model="dataForm" @keyup.enter.native="searchChange()">
      <el-form-item label="就诊卡号" prop="customerCard">
        <el-input v-model="dataForm.customerCard" placeholder="就诊卡号"></el-input>
      </el-form-item>
      <el-form-item label="患者姓名" prop="personName">
        <el-input v-model="dataForm.personName" placeholder="患者姓名"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="telPhone">
        <el-input v-model="dataForm.telPhone" placeholder="联系电话"></el-input>
      </el-form-item>
      <el-form-item label="就诊医生" prop="checkDoctorName">
        <el-input v-model="dataForm.checkDoctorName" placeholder="就诊医生"></el-input>
      </el-form-item>
      <el-form-item label="天数" prop="numberDayMin">
        <el-row>
          <el-col :span="11">
            <el-input v-model="dataForm.numberDayMin" placeholder="天数"></el-input>
          </el-col>
          <el-col class="line" :span="2" style="text-align: center;">至</el-col>
          <el-col :span="11">
            <el-input v-model="dataForm.numberDayMax" placeholder="天数"></el-input>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="复查类型" prop="reviewType">
        <el-select v-model="dataForm.reviewType" clearable>
          <el-option :value="1" label="初次"></el-option>
          <el-option :value="2" label="一周"></el-option>
          <el-option :value="3" label="一月"></el-option>
          <el-option :value="4" label="三月"></el-option>
          <el-option :value="5" label="半年"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="回访结果">
        <el-select v-model="dataForm.returnType" clearable>
          <el-option :value="1" label="已通知"></el-option>
          <el-option :value="2" label="已取消"></el-option>
          <el-option :value="3" label="待通知"></el-option>
          <el-option :value="0" label="未回访"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="dataForm.statusFlag" clearable>
          <el-option value="1" label="即将到期"></el-option>
          <el-option value="2" label="超期"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="部门">
        <el-input v-model="dataForm.deptName" placeholder="部门"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="searchChange">查询</el-button>
        <el-button type="default" icon="el-icon-delete" @click="searchReset">清空</el-button>
      </el-form-item>
    </el-form>
    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading">
        <el-table-column prop="customerCard" label="就诊卡号"></el-table-column>
        <el-table-column prop="returnType" label="回访结果" :formatter="returnTypeFormatter"></el-table-column>
        <el-table-column prop="returnDate" label="回访时间"></el-table-column>
        <el-table-column prop="personName" label="姓名">
          <template slot-scope="scope">
            <el-button type="text" @click="getCkCornealListByPersonId(scope.row.personId)">{{scope.row.personName}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="telPhone" label="联系电话"></el-table-column>
        <el-table-column prop="deptName" label="就诊部门"></el-table-column>
        <el-table-column prop="checkDoctorName" label="主检医生"></el-table-column>
        <el-table-column prop="reviewType" label="复查类型" :formatter="reviewTypeFormatter"></el-table-column>
        <el-table-column prop="checkDate" label="上次检查时间"></el-table-column>
        <el-table-column prop="nextCheckDate" label="预约时间"></el-table-column>
        <el-table-column prop="statusFlag" label="状态"></el-table-column>
        <el-table-column prop="numberDay" label="天数"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-if="permissions.pvm_ckreturnlog_add" type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id)">确认回访</el-button>
            <!-- <el-button v-if="permissions.pvm_ckcorneal_del" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
    <!-- 弹窗, 新增 / 修改 -->
    <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
    <get-list v-if="infoListVisible" ref="infoList" @refreshDataList="getDataList"></get-list>
  </div>
</template>

<script>
  import { fetchCkCornealReturnList, delCkCornealObj } from '@/api/pvm/ckcorneal'
  import { filterParams } from "@/util/tools"
  import TableForm from './returnlog-form'
  import GetList from './ckcornealList'
  import { mapGetters } from 'vuex'
  export default {
    data() {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        searchShow: true,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        infoListVisible: false
      }
    },
    components: {
      TableForm,
      GetList
    },
    created() {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions','userInfo'])
    },
    methods: {
      init() {
        this.getDataList();
      },
      // 获取数据列表
      getDataList() {
        this.dataListLoading = true
        let params1 = filterParams(this.dataForm);
        let params2 = {
          current: this.pageIndex,
          size: this.pageSize
        };
        fetchCkCornealReturnList(Object.assign(params2, params1)).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle(id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function() {
          return delCkCornealObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.mdg)
          }
        })
      },
      searchChange() {
        this.pageIndex = 1;
        this.getDataList()
      },
      // 搜索清空
      searchReset() {
        // this.$refs.searchForm.resetFields();
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
        this.getDataList(this.page)
      },
      handleSearchShow() {
        this.searchShow = !this.searchShow;
      },
      // 刷新回调
      refreshChange() {
        this.getDataList(this.page)
      },
      reviewTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case 1:
            return '初次'
            break
          case 2:
            return '一周'
            break
          case 3:
            return '一月'
            break
          case 4:
            return '三月'
            break
          case 5:
            return '半年'
            break
        }
      },
      returnTypeFormatter(row, column, cellValue, index) {
        switch (cellValue) {
          case 1:
            return '已通知'
            break
          case 2:
            return '已取消'
            break
          case 3:
            return '待通知'
            break
          case 0:
            return '未回访'
            break
        }
      },
      //  获取该患者所有的复查信息
      getCkCornealListByPersonId(personId) {
        this.infoListVisible = true;
        this.$nextTick(() => {
          this.$refs.infoList.init(personId);
        });
      },
    }
  }
</script>
